package com.ruoyi.project.cms.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cms.domain.Options;
import com.ruoyi.project.cms.service.OptionsService;

/**
 * 站点参数信息Controller
 * 
 * @author Su.Yuanlin
 * @date 2019-10-22
 */
@Controller
@RequestMapping("/site/option")
public class OptionsController extends BaseController
{
    private String prefix = "cms/option";

    @Autowired
    private OptionsService optionsService;

    @RequiresPermissions("cms:site:view")
    @GetMapping()
    public String site()
    {
        return prefix + "/site";
    }

    /**
     * 查询站点参数信息列表
     */
    @RequiresPermissions("cms:site:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Options options)
    {
        startPage();
        List<Options> list = optionsService.selectOptionsList(options);
        return getDataTable(list);
    }

    /**
     * 导出站点参数信息列表
     */
    @RequiresPermissions("cms:site:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Options options)
    {
        List<Options> list = optionsService.selectOptionsList(options);
        ExcelUtil<Options> util = new ExcelUtil<Options>(Options.class);
        return util.exportExcel(list, "site");
    }

    /**
     * 新增站点参数信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存站点参数信息
     */
    @RequiresPermissions("cms:site:add")
    @Log(title = "站点参数信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Options options)
    {
        return toAjax(optionsService.insertOptions(options));
    }

    /**
     * 修改站点参数信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        Options options = optionsService.selectOptionsById(id);
        mmap.put("options", options);
        return prefix + "/edit";
    }

    /**
     * 修改保存站点参数信息
     */
    @RequiresPermissions("cms:site:edit")
    @Log(title = "站点参数信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Options options)
    {
        return toAjax(optionsService.updateOptions(options));
    }

    /**
     * 删除站点参数信息
     */
    @RequiresPermissions("cms:site:remove")
    @Log(title = "站点参数信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(optionsService.deleteOptionsByIds(ids));
    }
}
